<div ng-controller="RenderFormController" id="formsection">
  <div loading="model.loading"></div>

  <div
    ng-if="!model.loading && formData != null && formData != undefined && (disableForm == null || disableForm == undefined || disableForm == false)"
    class="form-wrapper container-fluid"
  >
    <div ng-if="!outcomesOnly">
      <div ng-form="taskForm">
        <div class="formBind" ng-repeat="field in formData.fields" id="fieldContainer_{{ field.id }}" ng-class="{'oneCol':(field.layout.row==1),'towCol':(field.layout.row == 2),'threeCol':(field.layout.row == 3),'fourCol':(field.layout.row == 4)}">
          <form-element
            field="field"
            task-form="taskForm"
            control-callbacks="controlCallbacks"
            model="model"
            can-save="canSave"
          ></form-element>
        </div>
      </div>
    </div>
   
    <div ng-if="!formData.outcomes || formData.outcomes.length === 0" class="clearfix form-actions">
       <!-- 有表单时发起流程按钮 -->
      <div
        class="top-buttons"
        ng-if="processDefinitionId && (hideButtons == undefined || hideButtons == null || hideButtons == false) && (disableForm == undefined || disableForm == null || disableForm == false)"
      >
        <div class="btn-group pull-right">
          <div class="btn-toolbar pull-right">
            <button title="关闭窗口" class="btn btn-inverse" ng-click="closeModelWindow()">
              <i class="toolbar-button ng-scope glyphicon glyphicon-remove" data-toggle="tooltip" title="关闭窗口"></i>
            </button>
          </div>
        </div>
        <button
          id="form_save_button"
          class="btn btn-default"
          ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
          ng-click="saveForm()"
          ng-show="!processDefinitionId && !caseDefinitionId"
          translate="FORM.ACTION.SAVE"
        ></button>
        <button
          id="form_save_button"
          class="btn btn-default"
          ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
          ng-click="saveDRAFTForm('complete')"
          translate="FORM.ACTION.SAVE-DRAFT"
        ></button>
        <button
          id="form_complete_button"
          class="btn btn-default"
          ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
          ng-click="completeForm('complete')"
        >
          {{ getDefaultCompleteButtonText() }}
        </button>
      </div>

      <div class="top-buttons" ng-if="taskId">
        <div class="btn-group pull-right"  ng-if="!rev">
          <div class="btn-toolbar pull-right">
            <button title="关闭窗口" class="btn btn-inverse" ng-click="closeModelWindow()">
              <i class="toolbar-button ng-scope glyphicon glyphicon-remove" data-toggle="tooltip" title="关闭窗口"></i>
            </button>
          </div>
        </div>

        <!-- 流程实例详情关闭按钮 -->
      <div class="btn-group pull-right" ng-if="rev" ng-controller="TaskDetailController">
        <div class="btn-toolbar pull-right">
          <button title="关闭窗口" class="btn btn-inverse" ng-click="backToInstance()">
            <i class="toolbar-button ng-scope glyphicon glyphicon-remove" data-toggle="tooltip" title="关闭窗口"></i>
          </button>
        </div>
      </div>
      <!-- 有表单时按钮 -->
        <button
          class="btn btn-default"
          ng-click="urge()"
          ng-if="!((hideButtons == undefined || hideButtons == null || hideButtons == false) && (disableForm == undefined || disableForm == null || disableForm == false) && canSave) && canUrge"
        >
        {{ 'FORM.DEFAULT-OUTCOME.URGE' | translate }}
        </button>
        <button
          id="form_save_button"
          class="btn btn-default"
          ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
          ng-click="saveForm()"
          ng-show="!processDefinitionId && !caseDefinitionId"
          translate="FORM.ACTION.SAVE-DRAFT"
          ng-if="(hideButtons == undefined || hideButtons == null || hideButtons == false) && (disableForm == undefined || disableForm == null || disableForm == false) && canSave"
        ></button>
        <button
          class="btn btn-default"
          ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
          ng-click="openConfirmModal('cancel')"
          ng-if="isCancel"
        >
          {{ 'FORM.DEFAULT-OUTCOME.RECALL' | translate }}
        </button>
        <button
          class="btn btn-default"
          ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
          ng-click="openApprovalModal('reject')"
          ng-if="(hideButtons == undefined || hideButtons == null || hideButtons == false) && (disableForm == undefined || disableForm == null || disableForm == false) && !canSave"
        >
          {{ 'FORM.DEFAULT-OUTCOME.REJECT' | translate }}
        </button>
        <button
          id="form_complete_button"
          class="btn btn-default"
          ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
          ng-click="openApprovalModal('agree')"
          ng-if="(hideButtons == undefined || hideButtons == null || hideButtons == false) && (disableForm == undefined || disableForm == null || disableForm == false) && !canSave"
        >
          {{ getDefaultCompleteButtonText() }}
        </button>
        <button
          id="form_complete_buttons"
          class="btn btn-default"
          ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
          ng-click="completeForm('complete')"
          ng-if="(hideButtons == undefined || hideButtons == null || hideButtons == false) && (disableForm == undefined || disableForm == null || disableForm == false) && canSave"
        >
          {{ getDefaultCompleteButtonText() }}
        </button>
        <button
          class="btn btn-default"
          ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
          ng-click="openApprovalModal('transfer')"
          ng-if="(hideButtons == undefined || hideButtons == null || hideButtons == false) && (disableForm == undefined || disableForm == null || disableForm == false) && !canSave"
        >
          {{ 'FORM.DEFAULT-OUTCOME.TRANSFER' | translate }}
        </button>
        <button
          id="form_show_chart_button"
          class="btn btn-default"
          ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
          ng-click="showFlowChart()"
          translate="FORM.ACTION.FLOW-CHART"
        ></button>
        <button
          id="form_show_history_button"
          class="btn btn-default"
          ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
          ng-click="showApproveHistory()"
          translate="FORM.ACTION.APPROVE-HISTORY"
        ></button>
        <button class="btn btn-default" ng-click="showPrint()" translate="FORM.ACTION.FORM-PRINT"></button>       
      </div>
    </div>

    <!-- <div class="top-buttons" ng-if="taskId && rev">
      <div class="btn-group pull-right">
        <div class="btn-toolbar pull-right">
          <button title="关闭窗口" class="btn btn-inverse" ng-click="closeModelWindow()">
            <i class="toolbar-button ng-scope glyphicon glyphicon-remove" data-toggle="tooltip" title="关闭窗口"></i>
          </button>
        </div>
      </div>  
      <button
        class="btn btn-default"
        ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
        ng-click="openApprovalModal('transfer')"
        ng-if="!canSave && (rev==1)"
      >
        {{ 'FORM.DEFAULT-OUTCOME.TRANSFER' | translate }}
      </button>
      <button
        class="btn btn-default"
        ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
        ng-click="openApprovalModal('stop')"
        ng-if="rev==1"
      >
        {{ 'FORM.DEFAULT-OUTCOME.STOP' | translate }}
      </button>
      <button
        id="form_show_chart_button"
        class="btn btn-default"
        ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
        ng-click="showFlowChart()"
        translate="FORM.ACTION.FLOW-CHART"
      ></button>
      <button
        id="form_show_history_button"
        class="btn btn-default"
        ng-disabled="model.completeButtonDisabled || !model.valid || (disableOutcomes != undefined && disableOutcomes != null && disableOutcomes) || model.uploadInProgress"
        ng-click="showApproveHistory()"
        translate="FORM.ACTION.APPROVE-HISTORY"
      ></button>
      <button class="btn btn-default" ng-click="showPrint()" translate="FORM.ACTION.FORM-PRINT"></button>       
    </div> -->
  </div>


    <div ng-if="formData.outcomes && formData.outcomes.length > 0" class="clearfix form-actions">
      <div
        class="pull-right"
        ng-if="(hideButtons == undefined || hideButtons == null || hideButtons == false) && (disableForm == undefined || disableForm == null || disableForm == false)"
      >
        <button
          id="form_save_button"
          class="btn btn-default"
          ng-disabled="!model.valid || model.completeButtonDisabled || model.uploadInProgress"
          ng-click="saveForm()"
          ng-show="!processDefinitionId && !caseDefinitionId"
          translate="FORM.ACTION.SAVE"
        ></button>
        <button
          id="form_complete_button"
          class="btn btn-default"
          ng-disabled="!model.valid || model.completeButtonDisabled || model.uploadInProgress"
          ng-repeat="outcome in formData.outcomes"
          ng-click="completeForm(outcome)"
        >
          {{ outcome.name }}
        </button>
      </div>
    </div>

    <div ng-if="formData.selectedOutcome && formData.selectedOutcome.length > 0" class="clearfix form-actions">
      <div class="pull-right">
        <button id="form_complete_button" class="btn btn-default" ng-disabled="true">
          {{ formData.selectedOutcome }}
        </button>
      </div>
    </div>
  </div>
  <div ng-if="disableForm != null && disableForm != undefined && disableForm == true" >
    <div class="top-buttons" ng-if="taskId && !rev"  ng-controller="RenderFormController">
      <div class="btn-group pull-right">
        <div class="btn-toolbar pull-right">
          <button title="关闭窗口" class="btn btn-inverse" ng-click="closeModelWindow()">
            <i class="toolbar-button ng-scope glyphicon glyphicon-remove" data-toggle="tooltip" title="关闭窗口"></i>
          </button>
        </div>
      </div> 
    </div>
     <!-- 流程实例详情关闭按钮 -->
     <div class="top-buttons" ng-if="rev" ng-controller="TaskDetailController">
      <div class="btn-toolbar pull-right">
        <button title="关闭窗口" class="btn btn-inverse" ng-click="backToInstance()">
          <i class="toolbar-button ng-scope glyphicon glyphicon-remove" data-toggle="tooltip" title="关闭窗口"></i>
        </button>
      </div>
    </div>
    <div ng-if="disableFormText" class="text-center">
      <div class="help-container fixed">
        <div>
          <div class="help-text">
            <div class="description">
              {{ disableFormText | translate }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
